
<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" @submit.native.prevent >
            <el-form-item label="设备类型名称" prop="equipmentTypeName">
                <el-input v-model="queryParams.equipmentTypeName" placeholder="请输入设备类型名称" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
                <el-button icon="Refresh" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button type="primary" plain icon="Plus" @click="operateDialogRef.open()">新增</el-button>
            </el-col>
            <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" :data="list">
            <el-table-column type="index" width="50" align="center" label="序号">
                <template #default="scope">
                    <span>{{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}</span>
                </template>
            </el-table-column>
            <el-table-column label="设备类型名称" align="center" prop="typeName" />
            <el-table-column label="创建时间" align="center" prop="createTime" />
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                <template #default="scope">
                    <el-button link type="primary" icon="Edit" @click="operateDialogRef.open({id:scope.row.id})" >修改</el-button>
                    <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)">删除</el-button>
                </template>
            </el-table-column>
        </el-table>
        <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
            
        <TypeDialog ref="operateDialogRef" @refresh="getList" />
    </div>
</template>

<script setup name="EquipmentType">
import { getEquipmentTypeByPage, deleteEquipmentTypeById } from "@/api/simulation/equipmentType.js";
import TypeDialog from "./components/TypeDialog.vue";
const { proxy } = getCurrentInstance();

const list = ref([]);
const loading = ref(true);
const showSearch = ref(true);
const total = ref(0);
const operateDialogRef = ref(null);
const queryParams = ref({
    pageNum: 1,
    pageSize: 10,
    equipmentName: null,
})


/** 查询列表 */
function getList() {
    loading.value = true;
    getEquipmentTypeByPage(queryParams.value).then(response => {
       list.value = response.data.list;
        total.value = response.data.total;
        loading.value = false;
    });
}


/** 搜索按钮操作 */
function handleQuery() {
    queryParams.value.pageNum = 1;
    getList();
}

/** 重置按钮操作 */
function resetQuery() {
    proxy.resetForm("queryRef");
    handleQuery();
}


/** 删除按钮操作 */
function handleDelete(row) {
    proxy.$modal.confirm('是否确认删除此条数据项？').then(function () {
        return deleteEquipmentTypeById({ id: row.id });
    }).then(() => {
        getList();
        proxy.$modal.msgSuccess("删除成功");
    }).catch(() => { });
}

// function handleStatusChange(row) {
//   let text = row.status === "0" ? "启用" : "停用";
//   proxy.$modal.confirm('确认要"' + text + '""' + row.roleName + '"角色吗?').then(function () {
//     return changeRoleStatus(row.roleId, row.status);
//   }).then(() => {
//     proxy.$modal.msgSuccess(text + "成功");
//   }).catch(function () {
//     row.status = row.status === "0" ? "1" : "0";
//   });
// }


getList();
</script>
